/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bkt.service.app;

import bkt.model.person.Employee;
import bkt.service.model.person.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 *
 * @author Serge
 */
@Service("appEmployeeService")
public class AppEmployeeService {

    @Autowired
    private EmployeeService employeeService;

    public String saveNewEmployee(Employee employee) {

        if (isduplicate(employee) == false) {
            employeeService.persist(employee);
            System.out.println("EMP SAVED: " + employee.getEmpNumber());
            return "Saved";
            
        }
        else{
            System.out.println("Emp not saved!");
            return "NotnSaved";
        
        }
            
        
    }

    private boolean isduplicate(Employee employee) {
        boolean bool = true;
        Employee emp=null;
        try {
            emp = employeeService.getByPropertyName("empName", employee.getEmpName());
            System.out.println("Inside is duplicate Emp =: " + emp.getEmpName() + " ok");
        } catch (Exception e) {
            bool = false;
        }
        System.out.println("Boll value: " + bool);
        return bool;
    }
}
